package com.gxa.service.impl;

import com.gxa.common.PageInfo;
import com.gxa.common.R;
import com.gxa.mapper.QueryCommonMapper;
import com.gxa.pojo.*;
import com.gxa.service.QueryCommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class QueryCommonServiceImpl implements QueryCommonService{
    R r=new R();
    @Autowired(required = false)
    QueryCommonMapper queryCommonMapper;

    @Override
    public R querySupplierList(String condition,String supplier_Type_Name,Integer nowPage,Integer pageSize) {
        if(nowPage == null && pageSize == null){
                nowPage = PageInfo.NOWPAGE;
                pageSize = PageInfo.PAGESIZE;
        }
        pageSize = nowPage * pageSize;
        nowPage -= nowPage;
        List<Supplier> suppliers = queryCommonMapper.querySupplierList(condition,supplier_Type_Name,nowPage,pageSize);
        Integer sumPage = queryCommonMapper.querySumSupplier(condition,supplier_Type_Name);
        List list = new ArrayList();
        list.add(sumPage);
        list.add(suppliers);
        r.setCode(200);
        r.setMsg("操作成功");
        r.setData(list);
        return r;
    }

    @Override
    public R queryCustomerList(String condition, String customer_Type_Name, Integer nowPage, Integer pageSize) {
        if(nowPage == null && pageSize == null){
            nowPage = PageInfo.NOWPAGE;
            pageSize = PageInfo.PAGESIZE;
        }
        nowPage = (nowPage-1)*pageSize;
        List<Customer> customers = queryCommonMapper.queryCustomerList1(condition,customer_Type_Name,nowPage,pageSize);
        Integer sumPage = queryCommonMapper.querySumCustomer(condition,customer_Type_Name);
        List list = new ArrayList();
        list.add(sumPage);
        list.add(customers);
        r.setCode(200);
        r.setMsg("操作成功");
        r.setData(list);
        return r;
    }

    @Override
    public R queryStaffList() {
        List<Staff_Member_Manage> staff_member_manages = queryCommonMapper.queryStaffList();
        r.setCode(200);
        r.setMsg("操作成功");
        r.setData(staff_member_manages);
        return r;
    }


    @Override
    public R queerySupplierTypeList() {
        List<Supplier_Type> supplier_types = queryCommonMapper.querySupplierTypeList();
        r.setCode(200);
        r.setMsg("操作成功");
        r.setData(supplier_types);
        return r;
    }

    @Override
    public R queryCustomerTypeList() {
        List<Customer_Type> customer_types = queryCommonMapper.queryCustomerTypeList();
        r.setCode(200);
        r.setMsg("操作成功");
        r.setData(customer_types);
        return r;
    }


    @Override
    public R queryWarehouseList() {
        List<Warehouse> WarehouseList = queryCommonMapper.queryWarehouseList();
        r.setCode(200);
        r.setMsg("操作成功");
        r.setData(WarehouseList);
        return r;
    }

    @Override
    public R queryGoodsSave(String condition) {
        List<Map> GoodsSaveList = queryCommonMapper.queryGoodsSaveList(condition);
        r.setCode(200);
        r.setMsg("操作成功");
        r.setData(GoodsSaveList);
        return r;
    }

    @Override
    public R queryAccountList() {
        List<Account_Manage> accountList = queryCommonMapper.queryAccountList();
        r.setCode(200);
        r.setMsg("操作成功");
        r.setData(accountList);
        return r;
    }

    @Override
    public R queryGoodsList(String condition, Integer nowPage,Integer pageSize) {
        if(nowPage == null && pageSize == null){
            nowPage = PageInfo.NOWPAGE;
            pageSize = PageInfo.PAGESIZE;
        }
        nowPage = (nowPage-1)*pageSize;
        Integer sumGoods = queryCommonMapper.querySumGoods(condition);
        List<Map> goodsList = queryCommonMapper.queryGoodsList(condition,nowPage,pageSize);
        List list = new ArrayList();
        list.add(sumGoods);
        list.add(goodsList);
        r.setCode(200);
        r.setMsg("操作成功");
        r.setData(list);
        return r;
    }


}
